#include "StdAfx.h"
#include <QxtCore/QxtLogger>
#include "VSqlLog.h"

// VSqlLog ////////////////////////////////////////////////////////////////////

bool VSqlLog::m_canWrite = false;
bool VSqlLog::m_writeToMap = false;
VSqlLog::VMap1 VSqlLog::m_map1;

//
void VSqlLog::write(const QString &v1,const QString &v2)
{
	if (m_writeToMap)
	{
		int &count = m_map1[v1][v2];
		count++;
	}
	else
		writeX(v1,v2);
}

//
void VSqlLog::writeFromMap()
{
	QString v1,v2;

	VMap1::const_iterator i1 = m_map1.constBegin();
	while (i1 != m_map1.constEnd()) {
		v1 = i1.key();

		VMap2::const_iterator i2 = i1.value().constBegin();
		while (i2 != i1.value().constEnd()) {
			v2 = i2.key();
			writeX(v1,v2,i2.value());
			++i2;
		}
		
		++i1;
	}
}

//
void VSqlLog::writeX(const QString &v1,const QString &v2,int count)
{
	QString s; s
		= "[VSql][" + v1 + "]";

	if (count >= 0)
		s += "[" + QString("count=%1").arg(count) + "]";

	s	+= "\r\n" + v2 + "\r\n"
		+  QString().fill('-',80) + "\r\n";
	
	qxtLog->info(s);
}

// VSqlLog_script /////////////////////////////////////////////////////////////

bool VSqlLog_script::m_canWrite = false;

//
void VSqlLog_script::write(const QString &v1)
{
	QString s = "\r\n" + v1 + "\r\n\r\n";
	qxtLog->info(s);
}
